
var mNetworkFrequency = 1; //联网次数
var network = {
     //联网的接口
     getNetworking:function(type,promptView,wifiIp,phoneMac,callback){
       if(type == 0){
         mNetworkFrequency = 1
       }else {
        promptView.innerText = '再次联网...';
       }
       var parame = {
           userid: $api.getStorage(NewFiData.appParameKey.userId),
           siteAreaid:$api.getStorage(NewFiData.appParameKey.siteAreaid),
           ip: wifiIp,
           mac: phoneMac,
           visitType: 1,
           apName: $api.getStorage(NewFiData.wifiKey.wifiName)
       }
       var parames = common.getJSONParame(NewFiData.keyword.isAlive, JSON.stringify(parame));
       common.getConsole('联网',JSON.stringify(parames)+'..fwq..'+$api.getStorage(NewFiData.wifiKey.agentFWQ));
       common.ajax($api.getStorage(NewFiData.wifiKey.agentFWQ),parames,9,function(ret, err) {
           if (ret) {
               common.getConsole('联网请求结果', JSON.stringify(ret));
               if (ret.code ==1) {
                       if(ret.connect == 1){
                             promptView.innerText = '验证外网连接情况...';
                             seekAgent.judgeCloudNetworkState(function(state){
                                     if(state){
                                       callback(true);
                                       getNetworkToast('联网成功');
                                     }else {
                                        if(mNetworkFrequency >= 2){
                                            callback(false);
                                            getNetworkToast('联网失败');
                                        }else {
                                           mNetworkFrequency++;
                                           network.getNetworking(1,promptView,wifiIp,phoneMac,callback);
                                        }
                                     }
                             })
                       }else if(ret.connect == 2){
                            getNetworkToast('connect:'+ret.connect);
                             callback(false);
                       }else {
                             callback(false);
                             getNetworkToast('connect:'+ret.connect);
                       }
               }else {
                callback(false);
                common.getShowViewError(ret.code,ret.code.msg);
               }
           } else {
             common.getConsole('联网请求结果', JSON.stringify(err));
             callback(false);
             common.getShowViewError(err.code,ret.err.msg);
           }
       })
     },
}

 function getNetworkToast(msg){
  api.toast({
      msg: msg,
      duration: 2000,
      location: 'middle'
  });

}
